package com.ljt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.task.configuration.DefaultTaskConfigurer;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

@SpringBootApplication
@EnableTask
@EnableEurekaClient
public class TaskServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(TaskServerApplication.class, args);
	}
	@Bean
	public CommandLineRunner commandLineRunner() {
		return new TestCommandLineRunner();
	}
	@Bean
	public TaskListener taskListener() {
		return new TaskListener();
	}
	@Autowired
	private DataSource dataSource;

	@Bean
	public DefaultTaskConfigurer getTaskConfigurer() {
		return new DefaultTaskConfigurer(dataSource);
	}

	public static class TestCommandLineRunner implements CommandLineRunner {
		@Override
		public void run(String... strings) throws Exception {
			System.out.println("this is a Test about spring cloud task.");
//			try{
//				List<String> list = new ArrayList<>();
//				list.get(1);
//			}catch (Exception e){
//				System.out.println("Error");
//				throw e;
//			}
		}
	}
}
